using Ant.DbServiceInterface;
using Ant.Dto.PersonnelDto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;

namespace Ant.Service.PersonnelManagement.Conntroller
{
    [Route("ant/{controller}/{action}")]
    public class RoleController : Controller
    {
        private IPersonneDataService _dbService;
        public RoleController(IPersonneDataService dbService)
        {
            _dbService = dbService;
        }

        [HttpGet]
        public IActionResult Index()
        {
            return Ok("test");
        }


        [HttpGet]
        [Authorize(Roles = "Admin,Temp,Clerk,Manager")]
        public async Task<IActionResult> GetRole()
        {
            return Ok(await _dbService.GetRoleAsync());
        }

        [HttpPost]
        [Authorize(Roles = "Admin")]
        public IActionResult AddRole(string name)
        {
            if (_dbService.AddRole(name))
                return Ok();
            else
                return BadRequest("添加失败");

        }
    }
}